import java.util.concurrent.Semaphore;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86186
 * Date: 2023-10-02
 * Time: 13:12
 */
public class Test2 {
    public static void main(String[] args) throws InterruptedException {
        Semaphore semaphore = new Semaphore(4);
        semaphore.acquire();
        System.out.println("获取资源");
        semaphore.acquire();
        System.out.println("获取资源");
        semaphore.acquire();
        System.out.println("获取资源");
        semaphore.acquire();
        System.out.println("获取资源");
        semaphore.acquire();
        System.out.println("获取资源");
        semaphore.release();
        System.out.println("释放资源");
    }
}
